<?
class ArticlesFactory {
 
    var $articles;
 
    function Articles ( &$dbConn ) {
        // Pull the articles from the database
        $sql="SELECT * FROM articles";
        $result = $dbConn->query($sql);
        while ( $row = $result->getRow() ) {
            $this->articles[]=$row;
        }
    }
 
    // Factory method creates new instances of Article
    function & getArticle () {
        $row=each($this->articles);
        return new Article($row['value']);
    }
}

// The class built by the factory method
class Article {
    var $title;
    var $author;
    var $date; // Unix timestamp
    var $body;
    function Article($data) {
        $this->title=$data->title;
        $this->author=$data->author;
        $this->date=$data->date;
        $this->body=$data->body;
    }
 
    function title() {
        return htmlspecialchars($this->title);
    }
 
    function author() {
        return htmlspecialchars($this->author);
    }
 
    function date() {
        return date('F j, Y',$this->date);
    }
 
    function body() {
        return strip_tags($this->body, '<a><b><i><u><blockquote>');
    }
}


?>